package com.ny.wlw;

import java.util.*;

public class TestSet {
    public void addEmp(Set<Emp> empSet, Emp emp) {

        empSet.add(emp);
    }

    public void findAllEmp(Set<Emp> empSet) {
        for (Emp emp :empSet) {
            System.out.println(emp);
        }

    }

    public Emp findEmpName(Set<Emp> empSet, String ename) {
        for (Emp emp :empSet) {
            if (ename.equals(emp.getName())){
                return  emp;
            }
            }

        return null;
    }

    public void deleteEmpNumber(Set<Emp> empSet, String number) {
        Iterator<Emp> iterator=empSet.iterator();
        while (iterator.hasNext()){
            Emp emp =iterator.next();
            if (number.equals(emp.getNumber())) {
               iterator.remove();
                System.out.println(empSet);
                break;
            }
        }
    }

    public Emp findNumber(Set<Emp> empSet, String number) {
        for (Emp emp :empSet) {
            if (number.equals(emp.getNumber())) {
                return emp;
            }
        }
        return null;
    }


    public void updateEmpAge(Set<Emp> empSet, Emp emp) {
        Iterator<Emp> iterator=empSet.iterator();
        while (iterator.hasNext()){
            Emp oldEmp = iterator.next();
            if (emp.getNumber().equals(oldEmp.getNumber())) {
                iterator.remove();
                empSet.add(emp);
                System.out.println(empSet);
               break;
            }
        }


    }   public static void main(String[] args) {
        Emp emp1 = new Emp("1001", "小乔", 19);
        Emp emp2 = new Emp("1002", "大乔", 21);
        Set<Emp> set = new HashSet<>();
        set.add(emp1);
        set.add(emp2);
        for (Emp emp : set) {
            System.out.println(emp);
        }
        Scanner scanner = new Scanner(System.in);
        String ename = scanner.next();
        for (Emp emp : set) {
            if (ename.equals(emp.getName())) {
                System.out.println(emp);
            }
        }
    }



}

